/*
layui.use(['flow', 'api'], function () {
    var $ = layui.jquery, api = layui.api;
    var flow = layui.flow;
    flow.load({
        elem: '#blogListDiv',
        done: function (page, next) {
            var lis = [];
            $.get('/blog/blogList?pageNum=' + page, function (res) {
                var resData = res.data;
                layui.each(resData.list, function (index, item) {
                    lis.push(formatTemplate(item, $('script[type="text/templateList"]').html()));
                });
                next(lis.join(''), page < resData.totalPage);
            });
        }
    });
});*/
layui.use(['jquery', 'laypage'], function () {
    var $ = layui.jquery, laypage = layui.laypage;
    laypage.render({
        elem: 'blogListPager',
        curr: $('#currentPage').val(),
        count: $("#rows").val(),
        limit: $("#pageSize").val(),
        layout: ['count', 'prev', 'page', 'next'],
        jump: function (obj, first) {
            var curr = obj.curr;//得到当前页，以便向服务端请求对应页的数据。
            //首次不执行
            if (!first) {
                var keyword = $("#keyword").val();
                if (keyword === null || keyword === '') {
                    location.href = "/blog/index?pageNum=" + curr + "&tag=" + getUrlParam('tag')
                        + "&date=" + getUrlParam('date');
                } else {
                    location.href = "/searchBlog?pageNum=" + curr + "&keyword=" + keyword;
                }
            }
        }
    })
});

function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg); //匹配目标参数
    if (r !== null) return decodeURI(r[2]);
    return ""; //返回参数值
}